//
//  CMDBAreaManager.swift
//  CMDB
//
//  Created by 王磊 on 17/4/13.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBAreaManager: NSObject {
    static let getInstance: CMDBAreaManager = CMDBAreaManager()
    
    private override init() {
        super.init()
        
    }
}
extension CMDBAreaManager: CMDBAreaManagerDelegate {}

extension CMDBAreaManager {
    
    func queryAreas(areaParam: CMDBAreaParam, handler: CMDBAreasHandler, error: CMDBHttpErrorHandler, failure: CMDBHttpFailureHandler) {
        
        CMDBHttpManager.getInstance.request(areaParam.URLString(), param: areaParam.keyValues, success: { (sysTime, data, page) in
            
            let arr = CMDBAreaBean.objectArrayWithKeyValuesArray(data as! NSArray) as? Array<CMDBAreaBean>
            
            handler(areas: arr)
            
            }, error: error, failure: failure)
    }
}

extension CMDBAreaManager {
    
    func queryCountries(countryParam: CMDBCountriesParam, handler: CMDBCountriesHandler, error: CMDBHttpErrorHandler, failure: CMDBHttpFailureHandler) {
        
        CMDBHttpManager.getInstance.request(countryParam.URLString(), param: countryParam.keyValues, success: { (sysTime, data, page) in
            
            let arr = CMDBCountriesBean.objectArrayWithKeyValuesArray(data as! NSArray) as? Array<CMDBCountriesBean>
            
            handler(countries: arr)
            
            }, error: error, failure: failure)
        
    }
}